/*
 * inotify-sync - a simple file synchronizer and file system watcher
 * Copyright (C) 2010-2011, inotify-sync developers and inotify-sync contributors
 * Copyright (C) 2010-2011, Cohesion Network Security Studio
 *
 * inotify-sync is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * inotify-sync is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with inotify-sync; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/*
 * FILE:			Error.cpp
 * USAGE:			---
 * DESCRIPTION:		---
 * OPTIONS:			---
 * REQUIREMENTS:	---
 * BUGS:			---
 * NOTES:			---
 * AUTHOR:			LI Yiwei (mail:leeyiw@gmail.com)
 * COMPANY:			---
 * VERSION:			1.0
 * CREATED:			Thu Oct 20 18:09:57 CST 2011
 * REVISION:		---
 */

#include "Error.h"

Error::Error(int errnum,uint32_t error_id)
{
	this->errno=errnum;
	this->error_id=error_id;
}

Error::~Error()
{}

uint32_t
Error::get_error_id()
{
	return error_id;
}

string
Error::get_error_info()
{
	return string(strerror(errno));
}

string
Error::get_error_detail()
{
	string error_detail;
	switch(error_id)
	{
	case E_UNKNOWNERROR:
		error_detail="unknow error";
		break;
	case E_CONFNOTEXIST:
		error_detail="conf file not exist";
		break;
	case E_CONFPERMDENY:
		error_detail="conf file permission denied";
		break;
	case E_PROFPERMDENY:
		error_detail="profile file permission denied";
		break;
	case E_PROFCREATERR:
		error_detail="profile file create failed";
		break;
	case E_LOGFPERMDENY:
		error_detail="log file permission denied";
		break;
	case E_LOGFCREATERR:
		error_detail="log file create failed";
		break;
	case E_PROFNOTEXIST:
		error_detail="no such a profile";
		break;
	case E_INOTINITFAIL:
		error_detail="error occured calling inotify_init()";
		break;
	default:
		error_detail="nothing is error";
	}
	return error_detail;
}

void
Error::print_error_info()
{
	if(errno!=0)
		fprintf(stderr,"inotify-sync: %s\n",strerror(errno));
}

void
Error::print_error_detail()
{
	fprintf(stderr,"inotify-sync: %s\n",get_error_detail().c_str());
}

void
Error::print_error()
{
	print_error_info();
	print_error_detail();
}
